/**
 * 获取商户数据接口
 */

//引入Q模块
var Q = require('q');
//引入公共函数
var util = require('../../util');

//getStoreData接口入口文件
var index = function(getData, postData, config, _redis, db) {
	var deferred = Q.defer();
	//查询所有商户信息
	db.select('storeInfo', {}).then(function(storeInfo) {
		var storeData = {};
		//遍历商户信息取得商户名称
		for(var infoIndex in storeInfo) {
			for(var infoKey in storeInfo[infoIndex]) {
				if(infoKey == '_id') {
					continue;
				}
				storeData[infoKey] = storeInfo[infoIndex][infoKey];
				if(infoIndex == storeInfo.length - 1) {
					deferred.resolve(storeData);
				}
			}
		}
	}, function() {
		deferred.reject('-0040');
	});
	return deferred.promise;
}

//暴露接口
module.exports = {
	index: index
}